﻿using SHKF.B2C.YouZanYun.Model.Inter.MaterialCategory;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using WQDSkin.Forms.Controls;

namespace SHKF.B2C.Mannage.AdminUI.View.Yzy.Import
{
    /// <summary>
    /// frmSearchImageCategory.xaml 的交互逻辑
    /// </summary>
    public partial class frmSearchImageCategory : Window
    {
        private int category_id = 0;
        public string authority_id = "";

        public frmSearchImageCategory()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            GL.HttpClientYzy.authority_id = this.authority_id;

            this.LoadImageCategory();
        }

        private async void LoadImageCategory()
        {
            this.tvCategory.Items.Clear();

            int count = 0; //总图片数

            //未分组
            MaterialCategoryResult result = await GL.HttpClientYzy.GetMaterialCategory(2);
            if (result.data != null && result.data.Count > 0)
            {
                WQDTreeViewItem item2 = new WQDTreeViewItem();
                foreach (MaterialCategoryData data in result.data)
                {
                    item2.DataContext = data;
                    item2.Header = result.data[0].category_name + $"({data.count})";
                    tvCategory.Items.Add(item2);

                    count += data.count;
                }
            }

            //自定义
            result = await GL.HttpClientYzy.GetMaterialCategory(1);
            if (result.data != null && result.data.Count > 0)
            {
                WQDTreeViewItem item1 = new WQDTreeViewItem();
                item1.Header = "自定义分组";
                tvCategory.Items.Add(item1);

                foreach (MaterialCategoryData data in result.data)
                {
                    WQDTreeViewItem item3 = new WQDTreeViewItem();
                    item3.DataContext = data;
                    item3.Header = data.category_name + $"({data.count})";
                    item1.Items.Add(item3);

                    count += data.count;

                }

                item1.IsExpanded = true;
            }
        }

       
        public int CategoryID
        {
            get
            {
                return category_id;
            }
        }

        private void btnOK_Click(object sender, RoutedEventArgs e)
        {
            if (this.tvCategory.SelectedItem != null)
            {
                WQDTreeViewItem item1 = (WQDTreeViewItem)this.tvCategory.SelectedItem;
                MaterialCategoryData data = (MaterialCategoryData)item1.DataContext;
                category_id = data.category_id;
                this.DialogResult = true;
                this.Close();
            }
            else
            {
                MessageBox.Show("最少选择3张默认图片");
            }
        }

    }
}
